package com.kefu.chat.vo;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.kefu.chat.model.ChatReply;
import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kefu.common.context.KefuContext;
import com.kefu.common.vo.AbstractSearchVo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@ApiModel(description = "chat_reply")
public class ChatReplySearchVo extends AbstractSearchVo {

    @ApiModelProperty(name = "parentId", value = "上级id")
    private String parentId;
    @ApiModelProperty(name = "name", value = "内容")
    private String name;
    @ApiModelProperty(name = "type", value = "类型：0公共，1自己")
    private Integer type;

    @Override
    public LambdaQueryWrapper lambdaQuery() {
        LambdaQueryWrapper<ChatReply> wrapper = Wrappers.lambdaQuery(ChatReply.class);
        //上级id
        if (StringUtils.isNotBlank(parentId)) {
            wrapper.eq(ChatReply::getParentId, parentId);
        }
        //内容
        if (StringUtils.isNotBlank(name)) {
            wrapper.and(q -> q.like(ChatReply::getName, name).or().like(ChatReply::getKeyword, name));
        }
        //类型
        if (type != null) {
            wrapper.eq(ChatReply::getType, type);
            if (1 == type) {
                // 查自己的回复信息
                wrapper.eq(ChatReply::getAdminId, KefuContext.getKefuContext().getUserId());
            }
        }
        wrapper.eq(ChatReply::getTenantId, KefuContext.getKefuContext().getTenantId());
        wrapper.orderByAsc(ChatReply::getWeight);

        return wrapper;
    }
}